package com.hxkj.controller;

import com.github.pagehelper.PageInfo;
import com.hxkj.domain.po.Article;
import com.hxkj.domain.po.Tags;
import com.hxkj.service.ArticleService;
import com.platform.common.dispatcher.util.ResultStructUtils;
import com.platform.common.domain.result.ParameterDataStruct;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.result.ResultPageStruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * 文章控制层
 * <p>
 * created by zzx on 2018/6/6.
 */
@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    /**
     * 查询全站文章数据
     *
     * @param parameterDataStruct 文章对象 和 分页信息
     * @return 翻页数据
     * @throws Exception
     */
    @RequestMapping(value = "/getalllist", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<PageInfo<Article>> getAllArticleList(@RequestBody ParameterDataStruct<Article> parameterDataStruct) throws Exception {
        return () -> articleService.get(parameterDataStruct.getData() == null ? new Article() : parameterDataStruct.getData(),
                parameterDataStruct.getPageTo());
    }

    /**
     * 获取文章列表
     *
     * @param parameterDataStruct 文章对象 和 分页信息
     * @return 翻页数据
     * @throws Exception
     */
    @RequestMapping(value = "/getlist", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultPageStruct<Article>> getArticleList(@RequestBody ParameterDataStruct<Article> parameterDataStruct) throws Exception {
        return () -> ResultStructUtils.buildResultPageStruct(articleService.getArticleList(parameterDataStruct.getData() == null ?
                new Article() : parameterDataStruct.getData(), parameterDataStruct.getPageTo()), "param=value");
    }

    /**
     * @Description getArticleListByTags 根据tags获取文章列表
     **/
    @RequestMapping(value = "/getListByTags", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultPageStruct<Article>> getArticleListByTags(@RequestBody ParameterDataStruct<Article> parameterDataStruct) throws Exception{
        return () -> ResultStructUtils.buildResultPageStruct(articleService.getArticleListByTags(parameterDataStruct.getData() == null ?
                new Article() : parameterDataStruct.getData(), parameterDataStruct.getPageTo()), "param=value");
    }

    /**
     * 获取一条文章信息
     *
     * @param article
     * @return 文章信息
     * @throws Exception
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<Article>> getArticle(@RequestBody Article article) throws Exception {
        return () -> articleService.getArticle(article);
    }

    /**
     * 发布一篇文章
     *
     * @param article 文章信息
     * @throws Exception
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<Article>> saveArticle(@RequestBody Article article) throws Exception {
        return () -> articleService.saveArticle(article);
    }

    /**
     * 移除站点至回收站
     *
     * @param article 文章信息
     * @throws Exception
     */
    @RequestMapping(value = "/remove", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> removerArticle(@RequestBody Article article) throws Exception {
        return () -> articleService.removerArticle(article);
    }

    /**
     * 回收站 删除文章
     *
     * @param article 文章信息
     * @throws Exception
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> deleteArticle(@RequestBody Article article) throws Exception {
        return () -> articleService.deleteArticle(article);
    }

    /**
     * 修改文章
     *
     * @param article 文章信息
     * @throws Exception
     */
    @RequestMapping(value = "/modify", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> updateArticle(@RequestBody Article article) throws Exception {
        return () -> articleService.updateArticle(article);
    }

    /**
     * 文章恢复
     *
     * @param article 文章信息
     * @throws Exception
     */
    @RequestMapping(value = "/articlerecover", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> articleAudit(@RequestBody Article article) throws Exception {
        return () -> articleService.articleAudit(article);
    }

    /**
     * 文章审核/设置文章推荐级别
     *
     * @param article 文章信息
     * @throws Exception
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> articleRecover(@RequestBody Article article) throws Exception {
        return () -> articleService.articleRecover(article);
    }

    /**
     * 文章置顶
     *
     * @param article 文章信息
     * @throws Exception
     */
    @RequestMapping(value = "/stick", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> articleStick(@RequestBody Article article) throws Exception {
        return () -> articleService.articleStick(article);
    }

    /**
     * 查询 新闻推荐  热门百科 一级  二级 推荐  3篇文章
     *
     * @param article
     * @return 符合条件的Article对象List
     */
    @RequestMapping(value = "/getnews1", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<List<Article>>> getArticle1(@RequestBody Article article) throws Exception {
        return () -> articleService.getArticle1(article);
    }

    /**
     * 查询 新闻推荐  热门百科 三级 推荐      4篇文章
     *
     * @param article
     * @return 符合条件的Article对象List
     */
    @RequestMapping(value = "/getnews3", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<List<Article>>> getArticle3(@RequestBody Article article) throws Exception {
        return () -> articleService.getArticle3(article);
    }

    /**
     * 新闻推荐 三级 推荐   按页数来获取文章
     *
     * @param article
     * @return 符合条件的Article对象List
     */
    @ResponseBody
    @RequestMapping(value = "/getnews4", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<List<Article>>> getArticle4(@RequestBody Article article) throws Exception {
        return () -> articleService.getArticle4(article);
    }

    /**
     * 查询 期权行情   期权百科  首页模块  无分页
     *
     * @param article
     * @return 符合条件的Article对象List
     */
    @RequestMapping(value = "/getArticleMarket", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<List<Article>>> getArticleMarket(@RequestBody Article article) throws Exception {
        return () -> articleService.getArticleMarket(article);
    }

    /**
     * 查询 热门文章  取 10 条
     *
     * @param article
     * @return 符合条件的Article对象List
     */
    @RequestMapping(value = "/getHotArticle", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<List<Article>>> getHotArticle(@RequestBody Article article) throws Exception {
        return () -> articleService.getHotArticle(article);
    }

    /**
     * 查询咨询或曝光的总条数
     *
     * @param article
     * @return
     */
    @RequestMapping(value = "/getrightscount", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<Integer>> getRightsCount(@RequestBody Article article) throws Exception {
        return () -> articleService.getRightsCount(article);
    }

    /**
     * 获取上一篇文章
     */
    @RequestMapping(value = "/getprearticle", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<Article>> getPreArticle(@RequestBody Article article) throws Exception {
        return () -> articleService.getPreArticle(article);
    }

    /**
     * 获取下一篇文章
     */
    @RequestMapping(value = "/getnextarticle", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<Article>> getNextArticle(@RequestBody Article article) throws Exception {
        return () -> articleService.getNextArticle(article);
    }

    /**
     * @author Mr.zheng
     * @Description getArticleListByParam 根据参数获取文章列表
     * @Date 10:14 2018/7/20
     **/
    @RequestMapping(value = "/getArticleListByParam", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<List<Article>> getArticleListByParam(@RequestBody Article article) throws Exception {
        return () -> articleService.getArticleListByParam(article);
    }


    /**
     * @author Mr.zheng
     * @Description getHotTagsList 获取热门文章的标签列表
     * @Date 11:59 2018/7/20
     **/
    @RequestMapping(value = "/getTagsListByHotArticle", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<List<Tags>> getTagsListByHotArticle(@RequestBody Article article) throws Exception {
        return () -> articleService.getTagsListByHotArticle(article);
    }


    /**
     * @author Mr.zheng
     * @Description modifuArticleAsPath 修改静态资源路径
     * @Date 15:24 2018/7/24
     **/
    @RequestMapping(value = "/modifyArticleAsPath", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public void modifyArticleAsPath(@RequestBody Article article) throws Exception {
        articleService.modifyArticleAsPath(article);
    }

    /**
     * @author chenfangzhou
     * @Description getArticleListByParam 根据参数获取文章列表
     * @Date 10:14 2018/7/20
     **/
    @RequestMapping(value = "/getrightsArticlesByParam", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<List<Article>> getrightsArticlesByParam(@RequestBody Article article) throws Exception {
        return () -> articleService.getrightsArticlesByParam(article);
    }

    /**
     * @author Mr.zheng
     * @Description modifyHeat 根据文章ID和站点ID修改文章热度值
     * @Date 9:31 2018/8/9
     **/
    @RequestMapping(value = "/modifyHeat", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<Article>> modifyHeat(@RequestBody Article article) throws Exception {
        return () -> articleService.modifyHeat(article);
    }


    /**
     * @Description 根据模板和站点获取绑定的文章
     * @Date 2018年8月13日11:03:49
     * @Param [article]
     **/
    @RequestMapping(value = "/searchArticle", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<List<Article>>> searchArticle(@RequestBody Article article) throws Exception {
        return () -> articleService.searchArticle(article);
    }

    /**
     * @author Mr.zheng
     * @Description getArticleListByTime 根据文章id字符串获取30天以内的需要生成静态资源的文章列表
     * @Date 16:31 2018/8/14
     **/
    @RequestMapping(value = "/getArticleListByTime", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<List<Article>> getArticleListByTime(@RequestBody Article article) throws Exception {
        return () -> articleService.getArticleListByTime(article);
    }

    /**
     * @author Mr.zheng
     * @Description getArticleByTempletId 根据模板ID和站点ID去获取一条文章模拟数据
     * @Date 17:38 2018/8/16
     **/
    @RequestMapping(value = "/getArticleByTempletId", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<Article>> getArticleByTempletId(@RequestBody Article article) throws Exception {
        return () -> articleService.getArticleByTempletId(article);
    }

    /**
     * 获取最近一个月内的文章  chenfangzhou
     *
     * @param article
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getArticleInMonth", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<List<Article>> getArticleInMonth(@RequestBody Article article) throws Exception {
        return () -> articleService.getArticleInMonth(article);
    }

    /**
     * 自定义标签,获取相关推荐文章  chenfangzhou
     **/
    @RequestMapping(value = "/getCorrelationArticle", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    List<Article> getCorrelationArticle(@RequestBody Article article) throws Exception {
        return articleService.getCorrelationArticle(article);
    }

    /**
     * 自定义标签,获取每日最新文章  chenfangzhou
     **/
    @RequestMapping(value = "/getDailyArticleList", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    List<Article> getDailyArticleList(@RequestBody Article article) throws Exception {
        return articleService.getDailyArticleList(article);
    }

    /**
     * 自定义标签,获取每月最新文章  chenfangzhou
     **/
    @RequestMapping(value = "/getWeeklyArticleList", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    List<Article> getWeeklyArticleList(@RequestBody Article article) throws Exception {
        return articleService.getWeeklyArticleList(article);
    }

    @RequestMapping(value = "/selectArticleForUserCenter")
    public Callable<ResultDataStruct<List<Article>>> selectArticleForUserCenter() {
        return () -> articleService.selectArticleForUserCenter();
    }

    /**
     * 外汇网根据tags获取相关推荐文章
     * @param article
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getRecommendationArticle", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public List<Article> getRecommendationArticle(@RequestBody Article article) throws Exception {
        return articleService.getRecommendationArticle(article);
    }

    /**
     * 根据文章id字符串获取文章
     * @param article
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getArticleByIds", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public List<Article> getArticleByIds(@RequestBody Article article) throws Exception {
        return articleService.getArticleByIds(article);
    }

    /**
     * 根据文章编号查询文章
     * 用户中心收藏列表使用该接口
     * @author zhangheng
     * @param articleId
     * @return Article
     * @throws Exception
     */
    @RequestMapping(value = "/getArticleByArticleId", method = RequestMethod.POST)
    public Callable<ResultDataStruct<Article>> getArticleByArticleId(@RequestBody Long articleId) throws Exception{
        return () -> articleService.getArticleByArticleId(articleId);
    }

}

